var getTableId = function (tagName) {
    var tableJSONs = JSON.parse(getSql("select table_id, tag_name from log_toc", {
        dbgroup: "mssql",
        offset: 0,
        limit: -1,
        skip: 0,
        outfmt: "json"
    }));
    for (var i = 0; i < tableJSONs.length; i++) {
        if (tableJSONs[i].tag_name == tagName) {
            strRtn = tableJSONs[i].table_id;
        }
    }
    return strRtn;
}
var deleteHistoryData = function (tagName) {
    var tableId = getTableId(tagName);
    getSql("delete from log_" + tableId + " where DATEDIFF(d, time_stamp, GETDATE()) > 6", {
        dbgroup: "mssql",
        offset: 0,
        limit: -1,
        skip: 0,
        outfmt: "json"
    });
}
setTag("BACKCHAIN_RPM", getTag("BACKCHAIN_RPM_CURRENT"));
setTag("BACKCHAIN_VIB", getTag("BACKCHAIN_VIB_CURRENT"));
setTag("BACKCHAIN_POW", getTag("BACKCHAIN_POW_CURRENT"));
setTag("BACKCHAIN_RPM_CURRENT", 0);
setTag("BACKCHAIN_VIB_CURRENT", 0);
setTag("BACKCHAIN_POW_CURRENT", 0);

setTag("MAINCHAIN_RPM", getTag("MAINCHAIN_RPM_CURRENT"));
setTag("MAINCHAIN_VIB", getTag("MAINCHAIN_VIB_CURRENT"));
setTag("MAINCHAIN_POW", getTag("MAINCHAIN_POW_CURRENT"));
setTag("MAINCHAIN_RPM_CURRENT", 0);
setTag("MAINCHAIN_VIB_CURRENT", 0);
setTag("MAINCHAIN_POW_CURRENT", 0);

setTag("PAINT_PRESSURE", getTag("PAINT_PRESSURE_CURRENT"));
setTag("PAINT_NEG_PRESSURE", getTag("PAINT_NEG_PRESSURE_CURRENT"));
setTag("PAINT_ENV_TEMP", getTag("PAINT_ENV_TEMP_CURRENT"));
setTag("PAINT_ENV_HUMID", getTag("PAINT_ENV_HUMID_CURRENT"));
setTag("AUTO_PAINT_POW", getTag("AUTO_PAINT_POW_CURRENT"));
setTag("MANUAL_PAINT_POW", getTag("MANUAL_PAINT_POW_CURRENT"));
setTag("PAINT_LITF_POW", getTag("PAINT_LITF_POW_CURRENT"));
setTag("PAINT_PRESSURE_CURRENT", 0);
setTag("PAINT_NEG_PRESSURE_CURRENT", 0);
setTag("PAINT_ENV_TEMP_CURRENT", 0);
setTag("PAINT_ENV_HUMID_CURRENT", 0);
setTag("AUTO_PAINT_POW_CURRENT", 0);
setTag("MANUAL_PAINT_POW_CURRENT", 0);
setTag("PAINT_LITF_POW_CURRENT", 0);

setTag("DRYER_ENV_TEMP", getTag("DRYER_ENV_TEMP_CURRENT"));
setTag("DRYER_ENV_HUMID", getTag("DRYER_ENV_HUMID_CURRENT"));
setTag("DRYER_1_POW", getTag("DRYER_1_POW_CURRENT"));
setTag("DRYER_1_1TIC1", getTag("DRYER_1_1TIC1_CURRENT"));
setTag("DRYER_2_POW", getTag("DRYER_2_POW_CURRENT"));
setTag("DRYER_2_1TIC1", getTag("DRYER_2_1TIC1_CURRENT"));
setTag("DRYER_2_2T1C1", getTag("DRYER_2_2T1C1_CURRENT"));
setTag("DRYER_3_POW", getTag("DRYER_3_POW_CURRENT"));
setTag("DRYER_4_POW", getTag("DRYER_4_POW_CURRENT"));
setTag("DRYER_ENV_TEMP_CURRENT", 0);
setTag("DRYER_ENV_HUMID_CURRENT", 0);
setTag("DRYER_1_POW_CURRENT", 0);
setTag("DRYER_1_1TIC1_CURRENT", 0);
setTag("DRYER_2_POW_CURRENT", 0);
setTag("DRYER_2_1TIC1_CURRENT", 0);
setTag("DRYER_2_2T1C1_CURRENT", 0);
setTag("DRYER_3_POW_CURRENT", 0);
setTag("DRYER_4_POW_CURRENT", 0);

setTag("COOLER_BLOWER_POW", getTag("COOLER_BLOWER_POW_CURRENT"));
setTag("COOLER_DRAINER_POW", getTag("COOLER_DRAINER_POW_CURRENT"));
setTag("COOLER_1TIC1", getTag("COOLER_1TIC1_CURRENT"));
setTag("COOLER_BLOWER_POW_CURRENT", 0);
setTag("COOLER_DRAINER_POW_CURRENT", 0);
setTag("COOLER_1TIC1_CURRENT", 0);

setTag("FILTER_1_PRESS", getTag("FILTER_1_PRESS_CURRENT"));
setTag("FILTER_2_PRESS", getTag("FILTER_2_PRESS_CURRENT"));
setTag("FILTER_3_PRESS", getTag("FILTER_3_PRESS_CURRENT"));
setTag("FILTER_4_PRESS", getTag("FILTER_4_PRESS_CURRENT"));
setTag("FILTER_1_FLOW", getTag("FILTER_1_FLOW_CURRENT"));
setTag("FILTER_2_FLOW", getTag("FILTER_2_FLOW_CURRENT"));
setTag("FILTER_3_FLOW", getTag("FILTER_3_FLOW_CURRENT"));
setTag("FILTER_4_FLOW", getTag("FILTER_4_FLOW_CURRENT"));
setTag("PAINT_1_DRAINER_RPM", getTag("PAINT_1_DRAINER_RPM_CURRENT"));
setTag("PAINT_1_DRAINER_VIB", getTag("PAINT_1_DRAINER_VIB_CURRENT"));
setTag("PAINT_2_DRAINER_RPM", getTag("PAINT_2_DRAINER_RPM_CURRENT"));
setTag("PAINT_2_DRAINER_VIB", getTag("PAINT_2_DRAINER_VIB_CURRENT"));
setTag("WASTE_PUMP_POW", getTag("WASTE_PUMP_POW_CURRENT"));
setTag("PUMP_1_POW", getTag("PUMP_1_POW_CURRENT"));
setTag("PUMP_2_POW", getTag("PUMP_2_POW_CURRENT"));
setTag("PAINT_1_DRAINER_POW", getTag("PAINT_1_DRAINER_POW_CURRENT"));
setTag("PAINT_1_BLOWER_POW", getTag("PAINT_1_BLOWER_POW_CURRENT"));
setTag("PAINT_2_DRAINER_POW", getTag("PAINT_2_DRAINER_POW_CURRENT"));
setTag("PAINT_2_BLOWER_POW", getTag("PAINT_2_BLOWER_POW_CURRENT"));
setTag("FILTER_1_PRESS_CURRENT", 0);
setTag("FILTER_2_PRESS_CURRENT", 0);
setTag("FILTER_3_PRESS_CURRENT", 0);
setTag("FILTER_4_PRESS_CURRENT", 0);
setTag("FILTER_1_FLOW_CURRENT", 0);
setTag("FILTER_2_FLOW_CURRENT", 0);
setTag("FILTER_3_FLOW_CURRENT", 0);
setTag("FILTER_4_FLOW_CURRENT", 0);
setTag("PAINT_1_DRAINER_RPM_CURRENT", 0);
setTag("PAINT_1_DRAINER_VIB_CURRENT", 0);
setTag("PAINT_2_DRAINER_RPM_CURRENT", 0);
setTag("PAINT_2_DRAINER_VIB_CURRENT", 0);
setTag("WASTE_PUMP_POW_CURRENT", 0);
setTag("PUMP_1_POW_CURRENT", 0);
setTag("PUMP_2_POW_CURRENT", 0);
setTag("PAINT_1_DRAINER_POW_CURRENT", 0);
setTag("PAINT_1_BLOWER_POW_CURRENT", 0);
setTag("PAINT_2_DRAINER_POW_CURRENT", 0);
setTag("PAINT_2_BLOWER_POW_CURRENT", 0);